package com.harzone.commons.search.domain;

import java.util.ArrayList;
import java.util.List;


/**
 * 记录实体
 * @author ls
 * 2014年11月21日下午6:24:08
 */
public class Record implements Cloneable{
	
	private long version = 0;
	private float score = 0f;

	private List<Field> fields = new ArrayList<Field>();

	
	public Record addField(String name,Object value){
		this.fields.add(new Field(name, value));
		return this;
	}
	
	public Record addField(Field field){
		this.fields.add(field);
		return this;
	}
	
	public List<Field> getFields() {
		return fields;
	}

	public void setFields(List<Field> fields) {
		this.fields = fields;
	}
	
	/**
	 * 获取本条记录的字段
	 * @author ls
	 * 2014年11月21日下午5:28:04 
	 * @param name
	 * @return
	 */
	public Field getField(String name){
		for (Field field : fields) {
			if(field.getShowName().equals(name) || field.getName().equals(name)){
				return field;
			}
		}
		return null;
	}
	
	
	public void clear(){
		this.fields.clear();
	}

	
	public long getVersion() {
		return version;
	}


	public Record setVersion(long version) {
		this.version = version;
		return this;
	}


	public float getScore() {
		return score;
	}


	public Record setScore(float score) {
		this.score = score;
		return this;
	}

	@Override
	public String toString() {
		return "Record [version=" + version + ", score=" + score + ", fields="
				+ fields + "]";
	}

	
}
